class Solution:
    def minDeletions(self, s: str) -> int:
        counter = {}
        for string in s:
            if string not in counter:
                counter[string] = 0
            counter[string] += 1
        array = sorted(counter.values(), reverse=True)
        used = set()
        res = 0
        for val in array:
            while val in used and val >= 1:
                val -= 1
                res += 1
            used.add(val)

        return res
